import req from '@/http/reqdata'
let {reqgetuserdata,reqgetrmuserdata} = req

export default {
    namespaced:true, 
    state:{
        user:{
            name:localStorage.getItem('name'),
            token:localStorage.getItem('token')
        }
    },
    mutations:{
        setuserdata(state,value){
            state.user = value.data
            // console.log(state.searchdata);
        },

        setrmuser(state){
            state.user = {name:'',token:''}

        }
    },
    actions:{
         async requserdata(context,data){
          let newdata=  await reqgetuserdata(data)
        //   console.log(newdata);
        //   console.log(newdata);
        if(newdata.code === 200){
          context.commit('setuserdata',newdata)
          localStorage.setItem('name', newdata.data.name)
         localStorage.setItem('token',newdata.data.token)
        }else{
            return Promise.reject(newdata.message)
        }
         },

         async reqrmuser(context){
            console.log(111111111);
            let newdata = await reqgetrmuserdata()
            // console.log(newdata);
            if(newdata.code === 200){
                console.log(123456);
                localStorage.removeItem('name')
                localStorage.removeItem('token')
                context.commit('setrmuser')
            }
            
         }
    },
}